package by.msokoloff.javaweb2015.webapp.page.extra;

import java.math.BigDecimal;

import javax.inject.Inject;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.IModel;

import by.msokoloff.javaweb2015.datamodel.Extra;
import by.msokoloff.javaweb2015.services.ExtraService;
import by.msokoloff.javaweb2015.webapp.page.EntityListPage;

public class ExtraForm extends Form<Extra> {

	@Inject
	private ExtraService extraService;

	private Extra extra;

	public ExtraForm(String id, IModel<Extra> model) {
		super(id, model);
		add(new Label("id"));
		add(new TextField<String>("name"));
		add(new TextField<String>("descr"));
		add(new TextField<BigDecimal>("price"));
		
		add(new FeedbackPanel("feedbackpanel"));
		extra = model.getObject();
	}

	@Override
	public final void onSubmit() {
		extraService.createOrUpdate(extra);
		setResponsePage(new EntityListPage(Extra.class));
	}

	@Override
	public final void onError() {
		System.out.println("Error!");
	}
}
